<?php
class Game extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('game_model');
	}

	public function index()
	{
		$this->load->helper('url');
		
		$data['games'] = $this->game_model->get_games();
		$data['title'] = 'Games';

		$this->load->view('templates/man/header', $data);
		$this->load->view('man/game/index', $data);
		$this->load->view('templates/footer');
	}
	
	public function edit($id=NULL)
	{
		$this->load->helper('form', 'url');
		$this->load->library('form_validation');
		
		$data['title'] = 'Games';
		
		$this->form_validation->set_rules('title', 'Title', 'required');
		
		if ($this->form_validation->run() === FALSE)
		{
			if ($id !== FALSE)
			{
				$data['game'] = $this->game_model->get_game_by_id($id);
			}
			
			$this->load->view('templates/man/header', $data);
			$this->load->view('man/game/edit');
			$this->load->view('templates/footer');
		}
		else
		{
			$this->game_model->set_game();
			
			$this->load->view('templates/man/header', $data);
			$this->load->view('man/game/success');
			$this->load->view('templates/footer');
		}
	}
}